package com.zyh.system.service.impl;

import com.zyh.system.controller.MovieIndex;
import com.zyh.system.dao.impl.UserDaoImpl;
import com.zyh.system.domain.User;
import com.zyh.system.service.UserService;

import java.util.Map;
import java.util.Scanner;

/**
 * @Author zyh
 * @Date 2024/8/1 18:34
 * @Description UserService实现类
 */

public class UserServiceImpl implements UserService {
    public static final Scanner INPUT = new Scanner(System.in);
    public static final UserDaoImpl USER_DAO = new UserDaoImpl();
    public static final MovieIndex MOVIE_INDEX = new MovieIndex();

    /**
     * 登录功能
     *
     * @param map
     */
    @Override
    public void login(Map<String, String> map) {
        int count = 1;
        do {
            System.out.print("请输入账号：");
            String userName = INPUT.next();
            System.out.print("请输入密码：");
            String userPassword = INPUT.next();
            User user = new User(userName, userPassword);
            boolean is_login = USER_DAO.login(map, user);
            if (is_login) {
                System.out.println("登陆成功");
                MOVIE_INDEX.showIndex();
            } else {
                System.out.println("用户名或者密码错误");
                count++;
            }
        } while (count <= 3);
    }
}
